package day_2022_4_to_7.day48;

import java.util.Scanner;

/**
 * 二进制中1的个数
 * @author haomin
 * @date 2022/05/10 20:52
 **/
public class Day15_1_NumberOf1 {
    public static void main(String[] args){
        // 方法一 1 左移一位
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int num = in.nextInt();
            int flag = 1;
            int count = 0;
            while(flag != 0){
                if((num & flag) != 0){
                    count++;
                }
                flag = (flag << 1);
            }
            System.out.println(count);
        }
    }

    // 方法二 (num & num-1)
    public static void main2(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int num = in.nextInt();
            int count = 0;
            while(num != 0){
                num = (num & num-1);
                count++;
            }
            System.out.println(count);
        }
    }
}